<template>
    <div>
        <el-dialog :title="title" v-model="editFormVisible" :close-on-click-modal="false">
            <el-form ref="form" :model="form" :rules="rules" label-width="110px">
                <el-form-item label="产品名称">
                    <el-input v-model="form.FName"></el-input>
                </el-form-item>
                <el-form-item label="产品规格">
                    <el-input type="textarea" v-model="form.FModel"></el-input>
                </el-form-item>
                <el-form-item label="计量单位" placeholder="请选择"  prop="FUnitID">
                    <sy-select v-model="form.FUnitID"  valueKey="FID"
                               optionData="server/setting/SetType.ashx?cmd=GetOptions&FType=10">
                    </sy-select>
                </el-form-item>
                <el-form-item label="产品单价">
                    <el-input type="number" v-model="form.FPrice"></el-input>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input type="textarea" v-model="form.FNote"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click.native="editFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="save" :loading="loading">保存</el-button>
            </div>
      </el-dialog>
    </div>
</template>

<script>
    import util from '../../common/util'
    export default {
        data() {
            return {
                form: {},
                rules: {
                    FName: [{required: true,message: '产品名称', trigger: 'change'}]
                },
                loading:false,
                editFormVisible:false,
                title:''
            }
        },
        methods: {
            switchLoading(flag){
                this.loading = flag;
            },
            _openEdit(record) {
                this.editFormVisible = true;
                this.form = Object.assign({},record);
                this.title = '编辑';
                if(this.form.FUnitID==0)
                    this.form.FUnitID=''
            },
            _openAdd(record) {
                this.editFormVisible = true;
                this.form = Object.assign({FID:0},record);
                this.title = '新增';
            },
            save:function () {
                util.post("server/setting/Product.ashx?cmd=Save",this.form,this.switchLoading,result=> {
                    util.msgSuc("保存成功")
                    this.editFormVisible = false
                    this.$emit("onSaveSuc",this.form)
                })
            }
        },
        mounted() {

        }
    }
</script>
